<!doctype html>
<html class="x-admin-sm">
	<head>
		<meta charset="UTF-8">
		<title>国家智造·创新设计服务云平台</title>
		<meta name="renderer" content="webkit|ie-comp|ie-stand">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<!--<meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />-->
		<meta http-equiv="Cache-Control" content="no-siteapp" />
		<link rel="stylesheet" href="css/font.css">
		<link rel="stylesheet" href="css/login.css">
		<link rel="stylesheet" href="lib/layui/css/layui.css">
		<script type="text/javascript" src="js/jquery.min.js"></script>
		<script src="lib/layui/layui.js" charset="utf-8"></script>
		<script src="js/config.js" type="text/javascript" charset="utf-8"></script>
		<script src="js/ajax.js" type="text/javascript" charset="utf-8"></script>
		<script src="js/menu.js" type="text/javascript" charset="utf-8"></script>
		<script src="js/common.js" type="text/javascript" charset="utf-8"></script>
		<style>
			.queryAuthCode{
				height: auto;
			}
			.queryRegisterAuthCode{
				height: auto;
			}
			.chgLogin{
				box-shadow: 0 2px 3px 0 rgba(0,0,0,.2);
				padding: 20px;
				/*max-width: 1360px;*/
				margin-left: auto;
				margin-right: auto;
				/*margin-top: 10px;*/
				box-sizing: border-box;
				border-bottom: none;
			}
			.chgLoginBtn{
				width: 50%;padding: 0px;margin: 0px;border-bottom: none;
			}
		</style>
	</head>
	<body class="login-bg">
		<div class="login layui-anim layui-anim-up loginDiv">
			<div class="message">院士专家</div>
			<div id="darkbannerwrap"></div>
			<form method="post" class="layui-form">
				<input name="username" placeholder="用户名或手机号" type="text" lay-verify="required" class="layui-input">
				<hr class="hr15">
				<input name="password" lay-verify="required" placeholder="密码" type="password" class="layui-input">
				<hr class="hr15">
				<button value="登录" lay-submit lay-filter="login" style="width:100%;"   name="submitLogin" class="layui-btn layui-btn-normal submitLogin">
					登录</button>
				<hr class="hr20">
				<div class="layui-input" style="text-align:center;border: 0px;"><a href="" class="toRegister">没有账号，去注册</a></div>
				<div class="layui-input" style="text-align:center;border: 0px;"><a href="http://www.inno-design.org.cn" class="">返回首页</a></div>
			</form>
		</div>

		<div class="login layui-anim layui-anim-up registerDiv" style="display: none;min-width: 720px;">
			<div class="message">院士专家-注册账号</div>
			<div id="darkbannerwrap"></div>
			<form method="post" class="layui-form accountLoginForm">
				<div  style="display:flex;flex-direction: row;flex-wrap: nowrap;">
					<input name="registerPhoneNum"  placeholder="手机号" type="text" lay-verify="" class="layui-input registerPhoneNum">
					<!--<hr class="hr15">-->
					<input name="registerAuthCode" lay-verify="" placeholder="验证码" type="text"  class="registerAuthCode" style="margin-left: 20px;">
					<button class="layui-btn layui-btn-normal queryRegisterAuthCode">获取验证码</button>
				</div>
				<hr class="hr15">
				<div  style="display:flex;flex-direction: row;flex-wrap: nowrap;">
					<input name="registerUsername" placeholder="用户名" type="text" lay-verify="" class="layui-input registerUsername">
					<!--<hr class="hr15">-->
					<input name="registerEmail" placeholder="电子邮箱" type="text" lay-verify="" class="layui-input registerEmail" style="margin-left: 20px;">

				</div>
				<hr class="hr15">
				<div  style="display:flex;flex-direction: row;flex-wrap: nowrap;">
					<input name="registerPassword" lay-verify="" placeholder="密码" type="password" class="layui-input registerPassword">
					<!--<hr class="hr15">-->
					<input name="registerRepassword" lay-verify="" placeholder="再次输入密码" type="password" class="layui-input registerRepassword" style="margin-left: 20px;">
					<!--<hr class="hr15">-->
				</div>
				<hr class="hr15">
				<button   lay-filter="login" style="width:100%;" name="submitRegister" class="layui-btn layui-btn-normal submitRegister">
					注册
				</button>
				<hr class="hr20">
			</form>
			<div class="layui-input" style="text-align:center;border: 0px;" ><a href="" class="toLogin">有账号，去登录</a></div>
			<div class="layui-input" style="text-align:center;border: 0px;"><a href="http://www.inno-design.org.cn" class="">返回首页</a></div>
		</div>

		<script type="text/javascript">
			$(function() {
				function clearCookie() {
					var keys = document.cookie.match(/[^ =;]+(?=\=)/g);
					if (keys) {
						for (var i = keys.length; i--;) {
							document.cookie = keys[i] + '=0;path=/;expires=' + new Date(0).toUTCString();
							document.cookie = keys[i] + '=0;path=/;domain=' + document.domain + ';expires=' + new Date(0).toUTCString();
							document.cookie = keys[i] + '=0;path=/;domain=kevis.com;expires=' + new Date(0).toUTCString();
						}
					}
				}
				layui.use(['form', 'code', 'laydate','upload','layer','laytpl','element'], function() {
					var form = layui.form,
							layer = layui.layer;
					$("button[name='submitLogin']").on('click',function () {
						var params = {};
						params.account = $("input[name='username']").val();
						params.password = $("input[name='password']").val();
						params.loginType=1;
						params.roleId=1;
						// clearCookie();
						$.ajax({
							url: cgiMain.applicantLogin,
							dataType: 'json',
							data: params,
							xhrFields: {
								withCredentials: true
							},
							contentType: false,
							type: 'GET',
							cache: false,
							timeout: CFG.TIMEOUT,
							async:false,
							success: function(res) {
								if (res.code== '0000') {
									let role = null;

									for(let i = 0 ; i < res.result.role.length; i++){
										let item = res.result.role[i];
										if(item.id == 5 || item.id == 1){
											role = item;
											break;
										}
									}
									if(role){
										location.href = 'index.html';
									}else{
										layer.msg("此账号并不是用院士专家账号，请重试。请注意，创新人才、组织单位与院士专家的账号目前是各自独立的，不能互通！");
									}
								}else{
									layer.msg(res.msg);
								}

								return false;

							},
							error: function() {}});
						return false;
					});

					$(".toRegister").on("click",function () {
						$(".registerDiv").show();
						$(".loginDiv").hide();
						return false;
					});

					$(".toLogin").on("click",function () {
						$(".registerDiv").hide();
						$(".loginDiv").show();
						return false;
					});
					var countdown=60;
					function settime(obj) {
						if (countdown == 0) {
//							obj.removeAttribute("disabled");
							obj.removeClass("layui-btn-disabled");
//							obj.classList.remove("layui-btn-disabled")
							obj.html("获取验证码");
							obj.prop("disabled",false);
							countdown = 60;
							return;
						} else {
							obj.addClass("layui-btn-disabled");
							obj.html("重新发送(" + countdown + ")");
							obj.prop("disabled",true);
							countdown--;
						}
						setTimeout(function() {
									settime(obj) }
								,1000)
					}
					$(".queryRegisterAuthCode").on("click",function () {
						var params = {};
						params.phoneNum = $(".registerPhoneNum").val();
						if(!isMobileNumber(params.phoneNum)){
							return false;
						}
						params.type=1;
						params.roleId=1;
						getAuthCode(params,$(".queryRegisterAuthCode"));
						return false;
					});
					$(".queryAuthCode").on("click",function () {
						var params = {};
						params.phoneNum = $(".phoneNum").val();
						params.type=2;
						params.roleId=1;
						getAuthCode(params,$(".queryAuthCode"));
						return false;
					});

					function checkEmail(email){

//						var myReg=/^[a-zA-Z0-9_-]+@([a-zA-Z0-9]+\.)+(com|cn|net|org)$/;
						// /[\w!#$%&'*+/=?^_`{|}~-]+(?:\.[\w!#$%&'*+/=?^_`{|}~-]+)*@(?:[\w](?:[\w-]*[\w])?\.)+[\w](?:[\w-]*[\w])?/;
						var myReg=/[\w!#$%&'*+/=?^_`{|}~-]+(?:\.[\w!#$%&'*+/=?^_`{|}~-]+)*@(?:[\w](?:[\w-]*[\w])?\.)+[\w](?:[\w-]*[\w])?/;

						if(myReg.test(email)){
							return true;
						}else{
							layer.msg("邮箱格式不对!");
							return false;
						}
					}

					$(".submitRegister").on("click",function () {
						var params={};
						params.phoneNum = $(".registerPhoneNum").val();
						params.account = $(".registerUsername").val();
						params.password = $(".registerPassword").val();
						params.rePassword = $(".registerRepassword").val();
						params.email = $(".registerEmail").val();
						params.authCode = $(".registerAuthCode").val();
						params.roleId=1;
						params.registerType = 2;

						if(!params.phoneNum){
							layer.msg("手机号不能为空");
							return false;
						}
						if(!isMobileNumber(params.phoneNum)){
							return false;
						}
						if(!params.authCode){
							layer.msg("验证码不能为空");
							return false;
						}
						if(!params.account){
							layer.msg("账号名不能为空");
							return false;
						}

						if(!params.password || !params.rePassword || params.password !== params.rePassword){
							layer.msg("密码输入有误");
							return false;
						}
						if(!params.email){
							layer.msg("邮箱不能为空");
							return false;
						}
						if(!checkEmail(params.email)){
							return false;
						}


						AJAX.post(cgiMain.applicantRegister,
								params,
								function (res) {
									if(res.code == "0000"){
										$(".registerDiv").hide();
										$(".loginDiv").show();
										layer.msg("注册成功，请在此登录");
									}else{
										layer.msg(res.msg);
									}
									return false;
								});

						return false;

					});

					function isMobileNumber(phone) {
						var flag = false;
						var message = "";
						var myreg = /^(((13[0-9]{1})|(14[0-9]{1})|(16[0-9]{1})|(17[0-9]{1})|(15[0-3]{1})|(15[4-9]{1})|(18[0-9]{1})|(199))+\d{8})$/;
						if (phone == '') {
							// console.log("手机号码不能为空");
							message = "手机号码不能为空！";
						} else if (phone.length != 11) {
							//console.log("请输入11位手机号码！");
							message = "请输入11位手机号码！";
						} else if (!myreg.test(phone)) {
							//console.log("请输入有效的手机号码！");
							message = "请输入有效的手机号码！";
						} else {
							flag = true;
						}
						if (message != "") {
							layer.msg(message);
						}
						return flag;

					}

					function getAuthCode(params,obj) {
						$.ajax({
							url: cgiMain.applicantAuthCode,
							dataType: 'json',
							data: params,
							xhrFields: {
								withCredentials: true
							},
							contentType: false,
							type: 'GET',
							cache: false,
							timeout: CFG.TIMEOUT,
							async:false,
							success: function(res) {

								if (res.code== '0000') {
									layer.msg(res.result);
									settime(obj);
								}else{
									layer.msg(res.msg);
								}


							},
							error: function() {}});
					}


				});
			})
		</script>
	</body>
</html>
